package concurrent.atomic;

import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * 带票据的原子变量
 * 解决ABA问题
 * @author tuyou
 * @date 2020-08-17 23:29:03
 */
public class AtomicStampedReferenceTest {

    public static void main(String[] args) {
        AtomicStampedReference<Integer> stamp = new AtomicStampedReference<>(1, 0);
        System.out.println(stamp.getReference());
        System.out.println(stamp.getStamp());

        stamp.set(2, 1);
        System.out.println(stamp.getReference());
        System.out.println(stamp.getStamp());

        stamp.set(3, 2);
        System.out.println(stamp.getReference());
        System.out.println(stamp.getStamp());

        stamp.compareAndSet(4, 4, 2, 3);
        System.out.println(stamp.getReference());
        System.out.println(stamp.getStamp());
    }
}
